package gs.android.calcfeud;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;

public class Field extends Sprite {
	private Paint fp, tp;
	private Rect bounds;
	private RectF r;
	
	private int number;
	
	public Field(float x, float y, float width, float heigth, int number) {
		super(x, y, heigth, width, null);
		this.number = number;
		
		width = GamePersistor.SCREEN_WIDTH / 10;
		float half = GamePersistor.SCREEN_WIDTH / 2;
		float left = half + (getWidth() * (x - 1)) + 1f;
		float top = (half / 2 * 3) + (width / 2) + (width * y) + (width / 2) + 1f;
		float right = half + (width * x) - 1f;
		float bottom = (half / 2 * 3) + (width / 2) + (width * (y + 1)) + (width / 2) - 1f;
		
		r = new RectF(left, top, right, bottom);
		
		fp = new Paint();
		fp.setColor(Color.argb(255, 0, 255 - (number * 2), 0));
		
		tp = new Paint();
		tp.setColor(Color.WHITE);
		tp.setTextAlign(Align.CENTER);
		tp.setTypeface(Typeface.DEFAULT_BOLD);
		tp.setTextSize(GamePersistor.SCALE * 15);
		
		String text = "" + number;
		bounds = new Rect();
		tp.getTextBounds(text, 0, text.length(), bounds);
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}
	
	public RectF getR() {
		return r;
	}

	public boolean isColliding() {
		boolean res = false;
		
		return res;
	}

	@Override
	public void onDraw(Canvas c, int delta) {
		c.drawRoundRect(r, getWidth() / 10, getWidth() / 10, fp);
		c.drawText("" + number, r.left + (getWidth() / 2), r.top + (bounds.height() / 2) + (getWidth() / 2), tp);
	}
}